package com.freewater.library.lending.book.model.event;

import com.freewater.library.common.domain.DomainEvent;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.apache.commons.lang3.Validate;

import java.time.LocalDateTime;

/**
 * 预定已超时事件
 */
@Getter
@EqualsAndHashCode
public class BookInstanceReserveOverdueEvent implements DomainEvent {
    /**
     * 二维码
     */
    private final String qrCode;
    /**
     * ISBN
     */
    private final String isbn;
    /**
     * 读者Id
     */
    private final Long readerId;
    /**
     * 事件发生时间
     */
    private final LocalDateTime occurAt;

    public BookInstanceReserveOverdueEvent(String qrCode,
                                           String isbn,
                                           Long readerId) {
        this(qrCode, isbn, readerId, LocalDateTime.now());
    }

    public BookInstanceReserveOverdueEvent(String qrCode,
                                           String isbn,
                                           Long readerId,
                                           LocalDateTime occurAt) {
        Validate.notBlank(qrCode, "二维码不能为空");
        Validate.notBlank(isbn, "ISBN不能为空");
        Validate.notNull(readerId, "读者Id不能为空");
        Validate.notNull(occurAt, "事件发生时间不能为空");
        this.qrCode = qrCode;
        this.isbn = isbn;
        this.readerId = readerId;
        this.occurAt = occurAt;
    }

    @Override
    public LocalDateTime occurAt() {
        return this.occurAt;
    }
}
